package cn.hy.hot100;

import java.util.HashMap;
import java.util.Map;


// 两数之和
class Solution_1 {
    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> map = new HashMap<>();
        int[] ans = new int[2];
        for (int i = 0; i < nums.length; i++) {
            int other = target - nums[i];
            if (map.containsKey(other)) {
                ans[0] = i;
                ans[1] = map.get(other);
            }
            map.put(nums[i], i);
        }
        return ans;
    }
}